package cn.iocoder.yudao.module.member.user.service;

import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.module.api.member.vip.enums.VipTypeEnum;
import cn.iocoder.yudao.module.api.shop.info.ShopInfoApi;
import cn.iocoder.yudao.module.api.shop.staff.ShopStaffApi;
import cn.iocoder.yudao.module.api.shop.staff.enums.ShopStaffRoleEnum;
import cn.iocoder.yudao.module.member.agency.service.AppAgencyUserService;
import cn.iocoder.yudao.module.member.alliance.service.AppCloudAllianceUserService;
import cn.iocoder.yudao.module.member.bonus.service.app.AppBonusUserService;
import cn.iocoder.yudao.module.member.vip.service.AppVipUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 *  这里是文件说明
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/01/14
 * @see cn.iocoder.yudao.framework.security.core.service.SecurityFrameworkServiceImpl
 */
@Slf4j
@RequiredArgsConstructor
public class SecurityMemberServiceImpl implements SecurityMemberService {
    private final AppVipUserService appVipUserService;
    private final AppAgencyUserService appAgencyUserService;
    private final AppCloudAllianceUserService appCloudAllianceUserService;
    private final AppBonusUserService appBonusUserService;
    private final ShopInfoApi shopInfoApi;
    private final ShopStaffApi shopStaffApi;

    @Override
    public boolean isVipMember() {
        return appVipUserService.isValid(getLoginUserId(), VipTypeEnum.MEMBER);
    }

    @Override
    public boolean isMerchant() {
        return shopInfoApi.isOwnerByMemberUserId(getLoginUserId());
    }

    @Override
    public boolean isStaff() {
        return shopStaffApi.isStaff(getLoginUserId(), UserTypeEnum.MEMBER.getValue(), null);
    }

    @Override
    public boolean isVerifier() {
        return shopStaffApi.isStaff(getLoginUserId(), UserTypeEnum.MEMBER.getValue(), ShopStaffRoleEnum.VERIFIER.getValue());
    }

    @Override
    public boolean isRider() {
        return shopStaffApi.isStaff(getLoginUserId(), UserTypeEnum.MEMBER.getValue(), ShopStaffRoleEnum.RIDER.getValue());
    }

    @Override
    public boolean isCashier() {
        return shopStaffApi.isStaff(getLoginUserId(), UserTypeEnum.MEMBER.getValue(), ShopStaffRoleEnum.CASHIER.getValue());
    }

    @Override
    public boolean isSalesman() {
        return shopStaffApi.isStaff(getLoginUserId(), UserTypeEnum.MEMBER.getValue(), ShopStaffRoleEnum.SALESMAN.getValue());
    }

    @Override
    public boolean isVipMerchant() {
        return appVipUserService.isValid(getLoginUserId(), VipTypeEnum.MERCHANT);
    }

    @Override
    public boolean isAgency() {
        return appAgencyUserService.isValid(getLoginUserId());
    }

    @Override
    public boolean isCloudAlliance() {
        return appCloudAllianceUserService.isValid(getLoginUserId());
    }

    @Override
    public boolean isBonus() {
        return appBonusUserService.isValid(getLoginUserId());
    }

}
